package com.yupi.springbootinit.manager;

import cn.hutool.core.util.ObjectUtil;
import com.yupi.springbootinit.common.ErrorCode;
import com.yupi.springbootinit.exception.BusinessException;
import com.yupi.springbootinit.exception.ThrowUtils;
import com.yupi.yucongming.dev.client.YuCongMingClient;
import com.yupi.yucongming.dev.common.BaseResponse;
import com.yupi.yucongming.dev.model.DevChatRequest;
import com.yupi.yucongming.dev.model.DevChatResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @Author moresuo
 * @Date 2024/3/1 12:07
 * @注释
 */
@Service
public class AiManager {
    @Resource
    private YuCongMingClient yuCongMingClient;

    public String doChat(long modelId,String message){
        DevChatRequest devChatRequest = new DevChatRequest();
        devChatRequest.setModelId(modelId);
        devChatRequest.setMessage(message);
        BaseResponse<DevChatResponse> response = yuCongMingClient.doChat(devChatRequest);
        ThrowUtils.throwIf(ObjectUtil.isEmpty(response), new BusinessException(ErrorCode.SYSTEM_ERROR, "ai响应错误"));
        return response.getData().getContent();
    }
}
